package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

/**
 * Created by lenovo on 2016/11/30.
 */
public class IfReplyDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE =
      "com.isunland.palmstudysystem.ui.IfReplyDialogFragment.EXTRA_VALUE";
  private int[] choiceIds = new int[] { R.string.isTrue, R.string.isFalse, R.string.all };
  private String[] choiceStrings = new String[choiceIds.length];

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {

    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {
            CustomerDialog content = null;
            switch (which) {
              case 0:
                content = new CustomerDialog(getResources().getString(choiceIds[which]), "T");
                break;
              case 1:
                content = new CustomerDialog(getResources().getString(choiceIds[which]), "F");
                break;
              case 2:
                content = new CustomerDialog(getResources().getString(choiceIds[which]), "");
                break;
            }
            Intent i = new Intent();
            i.putExtra(EXTRA_VALUE, content);
            if (getTargetFragment() == null) return;
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
